#include <iostream>
#include <vector>
using namespace std;


void duplicateZeros(vector<int>& arr) 
{
	if(arr.size() == 0){
		return;
	}
	vector<int> temp(arr.size());
	int pointer1=0;
	int pointer2=0;
	while(pointer2 < temp.size()){
		if(arr[pointer1] == 0){
			temp[pointer2]=0;
			++pointer2;
			if(pointer2 >= temp.size()){
				break;
			}
			temp[pointer2]=0;
		}else{
			temp[pointer2]=arr[pointer1];
		}
		++pointer2;
		++pointer1;
	}
	for(int i=0;i<arr.size();++i){
		arr[i]=temp[i];
	}
}

int main(int argc, char *argv[])
{
	vector<int> a={8,4,5,0,0,0,0,7};
	duplicateZeros(a);
	for(int i=0;i<a.size();++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	return 0;
}

